<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "uview-ui/index.scss";
</style>

<script>
	export default {
		globalData:{
			timer:'',
			timeFun:''
		},
		onLaunch(option) {
			console.log(this.globalData)
			// let obj=this.$util.getUserInfo()
			// if(obj.ID){
			// 	this.setTime()
			// }
			this.globalData.timeFun=()=>{
				let _this=this
				return function(){
					_this.globalData.timer=setInterval(() => {
						_this.getDataNum()
					}, 1000 * 60*30)//一个小时
				}
			}
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods:{
			setTime(){
				this.globalData.timer=setInterval(() => {
					this.getDataNum()
				}, 1000 * 60*30)//一个小时
			},
			//获取数据
			getDataNum() {
				this.$axios.post('Device/XQueryNum', this.$util.getUserInfo(), p => {
					if (p.code == 0) {
						let _this=this
						clearInterval(this.globalData.timer)
						this.XQueryNum=JSON.parse(p.data)
						uni.showModal({
						  title: '提示',
						  content: `您当前有 ${this.XQueryNum.Table[0].YcNum}个设备异常，${this.XQueryNum.Table1[0].YjNum}预警数`,
						  success (res) {
						    if (res.confirm) {
								_this.setTime()
						      console.log('用户点击确定')
						    } else if (res.cancel) {
								_this.setTime()
						      console.log('用户点击取消')
						    }
						  }
						})
					}
				})
			},
		}
	}

</script>

<style lang="scss">
	/*每个页面公共css */
	@import './common.scss';
</style>
